package com.wang.leetcode;

/**
 * @Author: along
 * @Create: 2021/4/15 11:48
 * @Description:镜像二叉树
 */
public class Sword27 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        //设置一个临时节点 防止递归时找不到左右节点
        TreeNode res = new TreeNode(root.val);
        res.left = mirrorTree(root.right);
        res.right = mirrorTree(root.left);
        return res;
    }
}
